package com.robot.ad.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.robot.ad.pojo.Banner;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * banner数据访问接口
 *
 * @author wuyunbin
 */
public interface BannerDao extends JpaRepository<Banner, String>, JpaSpecificationExecutor<Banner> {
    /**
     * 根据状态查找轮播图列表
     *
     * @param status
     * @return
     */
    public List<Banner> findAllByStatusAndDeletedAtIsNullOrderBySortDesc(String status);

    /**
     * 根据status和areaId查找轮播图列表
     *
     * @param status
     * @param areaId
     * @return
     */
    @Query(value = "select * from ad.banner where status=?  and (area_list like %?% or area_list='') and deleted_at is null order by sort desc ", nativeQuery = true)
    public List<Banner> findAllByStatusAndAreaListOrderBySortDesc(String status, String areaId);
}
